/******************************************************************************
 * * setting_ut.c - dummy function for setting UT
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "lvgl.h"
#include "ui_type.h"
#include "../../../lvgl/hal/hal.h"
#include "mmi_modemadp_interface.h"
#include "inter_contacts_interface.h"
#include "inter_framework_interface.h"
#include "inter_common_ui_interface.h"
#include "inter_setting_interface.h"
#include "nav.h"
#include "setting_global.h"

TIMER_ID         dummy_tm;
MMI_MODEM_SIM_ID dummysimId;

VOID Setting_Test_Main(VOID)
{
    // hal_rtc_t time;
    // UINT32 seconds;

    printf("setting UT\n");
    UI_Common_Test_Main();
    Hal_Init();
    Setting_Init_Req();
    Display_Settings();

    // seconds = UI_Get_Timestamp_In_Second();

    // UI_Seconds_to_Time(seconds, &time);

    // printf("%d/%d/%d %d:%d:%d week:%d\n",time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour,
    // time.tm_min, time.tm_sec, time.tm_wday);
}

VOID Display_Normal_List_OnDestroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalListOnlyDesc = NULL;

    NormalListOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalListOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalListOnlyDesc);
}

UINT8 Display_Normal_List_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Ret           = 0;
    INT8  *Number       = NULL;
    INT8  NumberArr[11] = { "13224287051" };

    if (KEY_RELEASED != key_sta)
    {
        return(Ret);
    }

    if (KEY_OK == key_val)
    {
        Number = (INT8 *)Hal_Mem_Alloc(11);
        Hal_Mem_Set(Number, 0, 11);
        Hal_Mem_Copy(Number, NumberArr,11);

        Contacts_Setting_Select_Contact_Cnf(Number);
        printf("Send Contacts_Setting_Select_Contact_Cnf for UT\n");
    }
    else if (KEY_SOFTRIGHT == key_val)
    {   // return to previous UI
        Nav_Back(ACT_ID_ANY);
        Ret = 1;
    }

    return(Ret);
}

/**
 * Display Setting_Message_Alert
 * param (in) SimId: MMI_MODEM_SIM_ID
 * return void:
 */
VOID Display_Normal_List(VOID)
{
    UI_Normal_List_Only_Desc_t *NormalListOnlyDesc = NULL;
    Nav_Func_List_t            FuncList;

    NormalListOnlyDesc = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalListOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalListOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_CONTACT;
    NormalListOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalListOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalListOnlyDesc->List.ListButtonCnt = 1;
    NormalListOnlyDesc->List.ButtonList    = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t));
    Hal_Mem_Set(NormalListOnlyDesc->List.ButtonList, 0, sizeof(UI_Button_Desc_t));

    NormalListOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalListOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalListOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_CONTACT;

    NormalListOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalListOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalListOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalListOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalListOnlyDesc->KeyFunc = Display_Normal_List_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Normal_List_OnDestroy;

    Nav_Forward(ACT_ID_ANY, ACT_ID_CONTACTS, &FuncList, (VOID *)NormalListOnlyDesc);
}

/**
 * Enter number screening list
 * param (in) VOID
 * return  VOID
 */
VOID Contacts_Enter_Num_Scrn_List_Req(VOID)
{
    printf("%s\n", __FUNCTION__);
}

/**
 * Select contact in contacts APP, don`t display option button
 * If contact is empty, display warning and return to source APP
 * param (in) Type: IF_CONTACTS_SEL_CONTACT_TYPE
 * return  VOID
 */
VOID Contacts_Select_Contact_Req(IF_CONTACTS_SEL_CONTACT_TYPE Type)
{
    printf("Receive Contacts_Select_Contact_Req, display temp Contact UI for test\n");
    Display_Normal_List();

    /* IF_CONTACTS_CALL_SEL_ONE_CONTACT */
    /* IF_CONTACTS_SETTING_SEL_ONE_CONTACT */
    /* IF_CONTACTS_SMS_SEL_ONE_CONTACT */
    /* IF_CONTACTS_SMS_SEL_MULTI_CONTACTS */
}

VOID Framework_App_Register_Req(If_Framework_Reg_Info_t *RegInfo)
{
    printf("%s\n", __FUNCTION__);
}

/**
 *
 * Callback of Setting module, auto-back timer
 * param (in) Para: UINT32
 * return void:
 */
VOID Dummy_Timer_Timeout(UINT32 Para)
{
    Setting_Dual_Standby_Change_Resp();
}

/**
 * initiate confirm
 * param (in) void
 * return  void
 */
VOID Setting_Init_Cnf(Setting_Phone_Setting_t *PhoneSetting)        // to confirm init
{
    printf("%s\n", __FUNCTION__);
}

/**
 * to indicate that the phone setting has been restore
 * param (in) void
 * return  void
 */
VOID Setting_Phone_Setting_Restore_Ind(Setting_Phone_Setting_t *PhoneSetting)
{
    printf("%s\n", __FUNCTION__);
}

/**
 * get dual standby status
 * param (in) ServiceType: IF_SETTING_SERVICE_TYPE
 * return  UINT8: IF_SETTING_DEFAULT_SIM
 */
UINT8 Setting_Get_Defualt_Sim_Req(IF_SETTING_SERVICE_TYPE ServiceType)
{
    printf("%s\n", __FUNCTION__);
    return(0);
}

/**
 * indicate whether silent profile is selected, true means silent
 * param (in) Silent: BOOL(ture/false)
 * return  void
 */
VOID Setting_Ring_Silent_Ind(BOOL Silent)
{
    printf("%s\n", __FUNCTION__);
}

/**
 * indicate framework that RTC has been re-configurated
 * param (in) VOID
 * return  void
 */
VOID Setting_RTC_Reconfig_Ind(VOID)
{
    printf("%s\n", __FUNCTION__);
}

/**
 * phone setting change indication
 * param (in) PhoneSetting: If_Setting_Phone_Setting_t, alloc and free by caller
 * return  void
 */
VOID Setting_Phone_Setting_Chg_Ind(Setting_Phone_Setting_t *PhoneSetting)
{
    printf("%s\n", __FUNCTION__);
    if (  (IF_SETTING_CHANGE_MARK_DUAL_STAND_BY == (IF_SETTING_CHANGE_MARK_DUAL_STAND_BY & PhoneSetting->ChangeMark))
       && (  (IF_SETTING_SIM_1_STANDBY == PhoneSetting->DualStandby)
          || (IF_SETTING_SIM_2_STANDBY == PhoneSetting->DualStandby)))
    {
        UINT8 Para = 0;
        dummy_tm = Hal_Timer_Start(2000, Dummy_Timer_Timeout, (VOID *)&Para, FALSE);
    }
}
